#ifndef GAMEENGINE_GEOMETRY_COORDINATESYSTEMS_TRANSFORMER2D_ORIENTATION_H
#define GAMEENGINE_GEOMETRY_COORDINATESYSTEMS_TRANSFORMER2D_ORIENTATION_H

#include <GameEngine/Geometry/geometry_settings.h>

#include <GameEngine/Geometry/Location/vector2d.h>


#ifdef GAMEENGINE_NAMESPACES
namespace GameEngine {
#endif

namespace Transformer2DOrientation {
	//! Index in the 2x2 matrix of a two-dimensional transformer
	enum Index {
		//! First index
		First = 0,
		//! Second index
		Second = 1
	};
}

//! Class used to transform orientations between two 2D coordinate systems
/*!
 *  This class is a wrapper to a two-dimensional rotation matrix. It provides convenience
 *  functions that allow to build the rotation matrix from orientations that are known both
 *  in the source and in the destination spaces.
 *
 @sa Class Transformer2d for 2D transformations of spatial coordinates and class
     Transformer3dOrientation for transformation of 3D orientations.
 @note Most algorithms expect floating point operations.
       Type T should therefore not be an integer type
 */
template <class T>
class Transformer2dOrientation {

public:
	Transformer2dOrientation();
	Transformer2dOrientation(const Vector2d<T>& from1, const Vector2d<T>& from2, const Vector2d<T>& to1, const Vector2d<T>& to2);
	Transformer2dOrientation(const Transformer2dOrientation& rhs);
	virtual ~Transformer2dOrientation();
	Transformer2dOrientation& operator=(const Transformer2dOrientation& rhs);

	bool set_transformation(const Vector2d<T>& from1, const Vector2d<T>& from2, const Vector2d<T>& to1, const Vector2d<T>& to2);

	Vector2d<T> column1() const;
	Vector2d<T> column2() const;
	Vector2d<T> row1() const;
	Vector2d<T> row2() const;

	T matrix(Transformer2DOrientation::Index row, Transformer2DOrientation::Index column) const;
	T& matrix(Transformer2DOrientation::Index row, Transformer2DOrientation::Index column);

	Vector2d<T> transform(const Vector2d<T>& from) const;

	Transformer2dOrientation inverse(bool* ok = nil) const;

protected:
	//! Transformation matrix
	T matrix_[2][2];
};

#ifdef GAMEENGINE_NAMESPACES
} // namespace GameEngine
#endif

#include <GameEngine/Geometry/CoordinateSystems/transformer2d_orientation.hpp>

#endif
